package com.putong35.common.httprequest.responsecallbacks;

import java.util.List;


/**
 * ListBeanResponseListener
 * 1. 指定JavaBean类型和Class变量
 * 2. 父类的onSuccess不让使用
 * 3. 返回一个list bean列表给用户
 * 4. 保证list不为null
 *
 * @Author: Peng Weiwei
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2017-6-5
 * @Version: 1.0.0
 */
public abstract class ListBeanResponseListener<BeanT> extends StringResponseListener {
    Class<BeanT> beanTClass;

    public ListBeanResponseListener(Class<BeanT> beanTClass) {
        this.beanTClass = beanTClass;
    }

    public abstract void onSuccess(List<BeanT> beanList);

    @Override
    public void onSuccess(String response) {
        throw new RuntimeException("不可以回调此接口");
    }


    @Override
    public void deliverSuccessResponse(String response) {
        List<BeanT> beanList =getResponse().getDataListBean(beanTClass);
        onSuccess(beanList);
    }

    public boolean hasNextPage() {
        if (getResponse() == null) {
            return true;
        }
        return getResponse().hasNextPage();
    }

}
